package com.rabbiter.market.controller.user.goods;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rabbiter.market.common.web.response.JsonResult;
import com.rabbiter.market.domain.goods.goods_info.Goods;
import com.rabbiter.market.qo.goods_management.goods.QueryGoods;
import com.rabbiter.market.service.goods_management.goods.IGoodsService;
import com.rabbiter.market.vo.goods.GoodsListVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 用户端商品相关接口
 */
@RestController("userGoodsController")
@RequestMapping("/user/goods")
public class GoodsController {

    @Resource
    private IGoodsService goodsService;

    /**
     * 分页查询商品
     * @param qo
     * @return
     */
    @GetMapping("/get-all-goods")
    public JsonResult queryPageByQo(QueryGoods qo) {
        qo.setState(Goods.STATE_UP);
        Page<GoodsListVo> page = goodsService.queryPageByQo(qo);
        return JsonResult.success(page);
    }

    /**
     * 根据商品id查询商品详情
     * @param id
     * @return
     */
    @GetMapping("/get-goods-details-by-id")
    public JsonResult<GoodsListVo> queryGoodsById(Long id) {
        return JsonResult.success(goodsService.queryGoodsById(id));
    }

}
